package com.example.product.util;

import com.example.product.dao.CategoryDao;
import com.example.product.entity.CategoryEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class CategoryUtils {

    @Autowired
    private CategoryDao categoryDao;

    /**
     * 获取分类的路径 [父id,子id,孙id]
     * @param catelogId
     * @param path
     */
    public void getCatelogPath(Long catelogId, List<Long> path) {
        if (catelogId != 0) {
            CategoryEntity categoryEntity = categoryDao.selectById(catelogId);
            path.add(categoryEntity.getCatId());
            getCatelogPath(categoryEntity.getParentCid(),path);
        }
    };
}
